package Leetcode;

import NodeList.ListNode;

public class isPalindrome {
    private ListNode frontPointer;
    public boolean isPalindrome(ListNode head) {
        StringBuilder sb = new StringBuilder();
        while (head != null){
            sb.append(head.val);
            head = head.next;
        }
        int left = 0, right = sb.length() - 1;
        boolean reslut = false;
        while (left <= right){
            if (sb.charAt(left) == sb.charAt(right)){
                left++;
                right--;
                reslut = true;
            } else {
                return false;
            }
        }
        return reslut;
    }
    public boolean isPalindrome1(ListNode head) {
        frontPointer = head;
        return isP(head);
    }
    public boolean isP(ListNode node){
        if (node != null){
            if (!isP(node.next)){
                return false;
            }
            if (node.val != frontPointer.val){
                return false;
            }
            frontPointer = frontPointer.next;
        }
        return true;
    }
}
